const user = window.localStorage.getItem('user')

const init = {
    user: user ? JSON.parse(user) : null
}

export default (state = init, action) => {
    if(action.type === 'LOGIN'){
        window.localStorage.setItem('user', JSON.stringify(action.user))
        return {
            ...state,
            user: action.user
        }
    }
    return state
}